<template>
  <div class="data-item">
    <div class="keys">
      <span class="key">{{ data.label }}</span>
      <span class="key">{{ data.onlineLabel }}</span>
    </div>
    <div class="progress-bar">
      <div class="progress" :style="progressStyle"></div>
    </div>
    <div class="numbers">
      <CountTo class="number" :end="data.number" />
      <CountTo class="number" :end="data.onlineNumber" />
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'

interface DataItemInterface {
  label: string
  onlineLabel: string
  number: number
  onlineNumber: number
}

@Component({
  name: 'DataItem'
})
export default class DataItem extends Vue {
  /**
   * data
   */
  @Prop({
    type: Object,
    default: () => ({
      label: '',
      onlineLabel: '',
      number: 0,
      onlineNumber: 0
    })
  })
  data!: DataItemInterface

  get progressStyle() {
    const { number, onlineNumber } = this.$props.data
    const width = (Number(onlineNumber) / Number(number)) * 100 + '%'
    return {
      width
    }
  }
}
</script>
<style lang="scss" scoped>
.data-item {
  flex: 1;
  display: flex;
  flex-direction: column;

  .keys,
  .numbers {
    display: flex;
    width: 100%;
    justify-content: space-between;
  }

  .number {
    font-size: $font-size-extra-biggest;
    color: $color-white;
  }

  .progress-bar {
    position: relative;
    width: 100%;
    height: 4px;
    margin: 4px 0 12px;
    background-color: $bg-base;
    border-radius: 2px;

    .progress {
      position: absolute;
      right: 0;
      height: 100%;
      background: linear-gradient(90deg, #04aec1 0%, #026fe3 100%);
      border-radius: 2px;
    }
  }
}
</style>
